package com.xiumu.springbootlearn.exception;

import com.xiumu.springbootlearn.model.vo.ResultJSON;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

/**
 * @author xiumu
 * @date 2021年07月04日 23:45
 */
@RestControllerAdvice
public class GlobalExceptionHandler {

    @ExceptionHandler(Exception.class)
    public ResultJSON handlerException(Exception e) {
        System.out.println("全局异常处理！----》》》》" + e.getMessage());
        return new ResultJSON(500, "程序异常请联系管理员！");
    }

    @ExceptionHandler(BaseException.class)
    public ResultJSON handlerBaseException(BaseException e) {
        System.out.println("全局异常处理！----》》》》" + e.getExceptionContent());
        CommonException content = e.getExceptionContent();
        return new ResultJSON(content.getCode(), content.getMsg());
    }
}
